package com.ckzp.weixin.service.response;

import com.ckzp.core.util.XmlUtil;
import com.ckzp.weixin.service.ServiceRequest;
import com.ckzp.weixin.service.ServiceResponse;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 51594 on 2023/4/6.
 */
public class TuwenResponse implements ServiceResponse {


    public String ToUserName;

    public String FromUserName;

    public Long CreateTime = new Date().getTime();

    public String MsgType = "news";

    public int ArticleCount = 1;

    public TuwenArticle Articles;

    public String getToUserName() {
        return ToUserName;
    }

    public void setToUserName(String toUserName) {
        ToUserName = toUserName;
    }

    public String getFromUserName() {
        return FromUserName;
    }

    public void setFromUserName(String fromUserName) {
        FromUserName = fromUserName;
    }

    public Long getCreateTime() {
        return CreateTime;
    }

    public void setCreateTime(Long createTime) {
        CreateTime = createTime;
    }

    public String getMsgType() {
        return MsgType;
    }

    public void setMsgType(String msgType) {
        MsgType = msgType;
    }

    public int getArticleCount() {
        return ArticleCount;
    }

    public void setArticleCount(int articleCount) {
        ArticleCount = articleCount;
    }


    public TuwenArticle getArticles() {
        return Articles;
    }

    public void setArticles(TuwenArticle articles) {
        Articles = articles;
    }

    public void addArticle(TuwenItem article) {
        if (Articles == null) Articles = new TuwenArticle();
        Articles.item.add(article);
        ArticleCount = Articles.item.size();
    }

    public void addArticle(String title, String desc, String pic, String url) {
        if (Articles == null) Articles = new TuwenArticle();
        Articles.addArticle(title, desc, pic, url);
        ArticleCount = Articles.item.size();
    }

    public String toXml() {
        return XmlUtil.toXml(this);
    }


    public static TuwenResponse n() {
        return new TuwenResponse();
    }

    /**
     * @param req
     * @return
     */
    public static TuwenResponse init(ServiceRequest req) {
        TuwenResponse res = TuwenResponse.n();
        res.setFromUserName(req.getToUserName());
        res.setToUserName(req.getFromUserName());
        res.setMsgType("news");
        //  res.setCreateTime(req.getCreateTime());
        return res;
    }


    public static void main(String[] arg) {
        TuwenResponse response = TuwenResponse.n();
        response.addArticle("测试", "备注", "", "http://www.sina.com.cn/");
        //response.addArticle("测试2", "备注2", "", "http://www.sina.com.cn/");
        System.out.println(response.toXml());
    }

}
